package com.example.mobile2021606145zbq0617homework;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class RV_Adapter extends RecyclerView.Adapter<RV_Adapter.ViewHolder>{
    List<Person>list;

    public RV_Adapter(List<Person> list) {
        this.list = list;
    }

    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull RV_Adapter.ViewHolder holder, int position) {
        Person person = list.get(position);
        holder.TVName.setText("" + person.getName());
        holder.TVVocation.setText("" + person.getVocation());
        holder.TVSalary.setText("" + person.getSalary());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView TVName, TVVocation, TVSalary;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            TVName = itemView.findViewById(R.id.tvMainName);
            TVVocation = itemView.findViewById(R.id.tvMainVocation);
            TVSalary = itemView.findViewById(R.id.tvMainSalary);
        }
    }
}
